{template 'header'}
<body>
<div class="x-body">
    <h2>第一步：上传xlsx表格文件</h2>

    <button type="button" class="layui-btn" id="upload">
        <i class="layui-icon">&#xe67c;</i>上传xlsx文件
    </button>

    <hr>
    <h2>第二步：选择需要导入的文件</h2>

    <div class="layui-form-item">
        <select name="targetfile" id="targetfile">
            <option value="">请选择未导入文件</option>
            {loop $list $item}
                <option value="{$item}">{$item}</option>
            {/loop}
        </select>
    </div>

    <hr>
    <h2>第三步：确认导入</h2>

    <div class="layui-form-item">
        <button class="layui-btn layui-btn-warning" onclick="ok()">确认导入</button>
    </div>

    <hr>
    <h2>Excel文件样例</h2>
    <table class="layui-table">
        <a style="background: green;border-color: green;" class="layui-btn layui-btn-danger"
           href="{php echo $this->createWebUrl('member_import',['op'=>'default'])}">导出Excel样例表格</a>
    </table>
</div>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload', //绑定元素
            url: '{php echo $this->createWebUrl("member_import",["op"=>"upload"])}', //上传接口
            size:4*1024,//4M
            accept:'file',
            done: function(res){
                layer.msg(res.msg,function () {
                    if(res.code){
                        location.reload()
                    }
                })
            },error: function(){
                layer.msg("网络异常，请稍后重试", {icon: 0});
            }
        });
    });
    function ok() {
        var targetfile = $('#targetfile').val()
        if (!targetfile) {
            layer.msg('请选择需要导入的文件', {icon: 1})
        }
        var url = '{php echo $this->createWebUrl("member_import",["op"=>'import1'])}'
        $.post(url, {targetfile: targetfile}, function (ret) {
            layer.msg(ret.msg,{end:function(){
                    location.reload()
                }})
        }, 'json')
    }
</script>
</body>
</html>